#include "GameObject.h"
#include "Physics/Box2DVehicle.h"

mtBEGIN(GameObject)
	mtBASE(ECS::Assembly);

	mtSIGNAL(eventSetPosition, __setPosition);
	mtSIGNAL(eventUpdate, __update);
mtEND
// AI

// Game Object
GameObject::GameObject() 
{

}

GameObject::~GameObject()
{

}

bool GameObject::init()
{
    this->createComponent<Body>()->onStart();
    this->createComponent<SceneNode>();

    CCDirector::sharedDirector()->getScheduler()->scheduleUpdateForTarget(this, 0, false);
    return true;
}

void GameObject::update( float dt )
{
	eventUpdate(dt);
    //if (mAI == nullptr)
    //{
    //    mAI = getComponent<AI>();
    //}
    //if (mAI) mAI->update(dt);
    //const b2Vec2& pos = mPhysics->getBody()->GetPosition();
    //
    //mGraphics->getNode()->setRotation(mPhysics->getBody()->GetAngle()/* * M_PI * 2.0f*/);
    //mGraphics->getNode()->setPosition(ccp(pos.x * 64.0f, pos.y * 64.0f));
}

void GameObject::setPosition( const Vector& pos )
{
	eventSetPosition(pos);
    //mPhysics->setPosition(pos);
    //mGraphics->getNode()->setPosition(ccp(pos.x * 64.0f, pos.y * 64.0f));
}

lodestar::Vector GameObject::getPosition() const
{
    const b2Vec2& vec = this->getComponent<Body>()->getBody()->GetPosition();
    return lodestar::Vector(vec.x, vec.y);
}

World::World() : _map(new MapZone())
{
    _map->init(32, 32);
}

World::~World()
{

}

bool World::init()
{
    mWorld = new b2World(b2Vec2(0.0f, 0.0f));

    return true;
}

GameObject* World::createObject()
{
    GameObject* obj = new GameObject();
    obj->init();

    mObjects.push_back(obj);
    return obj;
}

